﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JMY_Models;
using JMY_IDAL;
using System.Data.SqlClient;
using System.Data;
namespace JMY_DAL
{
    public class LoginDAL : JMY_IDAL.LoginIDAL
    {
        SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=HospitalMessage;User ID=sa;password=19961218;");
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int LoginsInfo(T_User_Infos_Model m)
        {
            int i;
            try
            {
                conn.Open();
                string sql = string.Format("insert into T_User_Infos values('{0}','{1}')",m.T_User_Phone,m.T_User_Pwd);
                SqlCommand cmd = new SqlCommand(sql, conn);
                i = cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return i;
        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public int UserLogin(T_User_Infos_Model s)
        {
            int i;
            try
            {
                conn.Open();
                string sql = string.Format("select T_User_ID from T_User_Infos where T_User_Phone='{0}' and T_User_Pwd='{1}'",s.T_User_Phone,s.T_User_Pwd);
                SqlCommand cmd = new SqlCommand(sql, conn);
                i = Convert.ToInt32(cmd.ExecuteScalar());
            }
            catch (Exception ex)
            {

                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return i;
        }
    }
    
}
